import { speechRec, speechSyn } from "./speech.js";
// 语音识别配置
const __config = {
  continuous: true, // 多次识别语音
  interimResults: false, // 在识别过程中是否允许更新识别的结果
  lang: "zh-CN", // 语言
};

export const init = (config = __config) => {
  return { speechRec: speechRec(config), speechSyn };
};
// 初始化需要获取的标签
export const initElem = (ids) => {
  const elems = {};
  getElemId(elems, ids);
  return elems;
};
export const elems = initElem(["send_msg", "rec_msg"]);
// 通过id获取dom元素
function getElemId(source, ids) {
  ids.forEach((id) => (source[id] = document.querySelector(`#${id}`)));
}
// 获取语音识别结果
export const getLastMsg = (event) => {
  const len = event.results.length;
  const lastOne = event.results[len - 1];
  const { transcript } = lastOne[0];
  return transcript;
};
